package com.fosu.dao;

import com.fosu.domain.Feedback;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @ClassName FeedbackDao
 * @Description 反馈意见持久层
 * @Author 夜天冥
 * @Date 2020/11/14 20:33
 * @Version 1.0
 */
@Mapper
@Repository
public interface FeedbackDao {
    /**
     * @Author 夜天冥
     * @Description //查询所有反馈意见  * @Date  2020/11/14
     * @Param
     * @return List<Feedback> 反馈意见集合
     **/
    @Select("select * from feedback")
    @Results(id = "feedbackMap", value = {
            @Result(id = true, property = "feedbackId", column = "feedback_id"),
            @Result(property = "userId", column = "user_id"),
            @Result(property = "feedbackTitle", column = "title"),
            @Result(property = "feedbackDetail", column = "detail"),
            @Result(property = "phone", column = "phone"),
            @Result(property = "date", column = "date"),
//            @Result(property = "feedbackImgs",
//                    column = "feedback_id",
//                    javaType = java.util.List.class,
//                    many = @Many(select = "com.fosu.dao.FeedbackImgDao.findImgsById")),

    })
    List<Feedback> findAllFeedback();

    /**
     * @Author 夜天冥
     * @Description //插入反馈意见  * @Date  2020/11/14
     * @Param feedback
     * @return
     **/
    @Insert("insert into feedback(user_id,title,detail,phone,date)" +
            "values(#{userId},#{feedbackTitle},#{feedbackDetail},#{phone},now())")
    @Results(id = "feedbackMap",value = {
            @Result(id = true,property = "feedbackId",column = "feedback_id"),
            @Result(property = "userId",column = "user_id"),
            @Result(property = "feedbackTitle",column = "title"),
            @Result(property = "feedbackDetail",column = "detail"),
            @Result(property = "phone",column = "phone"),
    })
    @Options(useGeneratedKeys = true, keyProperty = "feedbackId", keyColumn = "feedback_id")
    void saveFeedback(Feedback feedback);
}
